package com.pomelo.tiku.impls;

import android.app.Activity;

import com.pomelo.tiku.beans.LoginBean;
import com.pomelo.tiku.beans.RegisterBean;
import com.pomelo.tiku.interfaces.Contract;

import java.util.HashMap;

/**
 * @author liuxiangwang
 * @date .
 */
public class LoginPresenter implements Contract.ILoginPresenter {
    private Contract.ILoginModel iLoginModel;
    private Contract.ILoginView iLoginView;

    public LoginPresenter(Contract.ILoginModel model, Contract.ILoginView view) {
        this.iLoginModel = model;
        this.iLoginView = view;
    }


    @Override
    public void request(String url, HashMap<String,String> header, HashMap<String,String> data) {
        iLoginModel.login(url,header,data,true,new Contract.ILoginModel.ILoginResult() {

            @Override
            public void onStart() {
                iLoginView.showLoading();
            }

            @Override
            public void onSuccess(LoginBean loginBean) {
                iLoginView.loginSuccess(loginBean);
                iLoginView.stopLoading();
            }

            @Override
            public void onFailed(String message) {
                iLoginView.loginFailed(message);
                iLoginView.stopLoading();
            }

            @Override
            public void onHttpFailed(String message) {

                iLoginView.loginFailed(message);
                iLoginView.stopLoading();
            }
        });
    }
}
